const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");

/**
 * @type {import('webpack').Configuration}
 */
module.exports = {
  mode: "development",
  entry: "./index.js",
  output: {
    path: path.join(__dirname, "dist"),
    filename: "[name].js",
    publicPath: "auto",
    clean: true,
  },
  devtool: "eval-cheap-module-source-map",
  cache: {
    type: "filesystem",
  },
  optimization: {
    splitChunks: {
      minSize: 1 * 1024,
      chunks: "all",
      name: "common",
    },
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: "index.html",
      template: path.resolve(__dirname, "./public/index.html"),
    }),
    new ModuleFederationPlugin({
      filename: "app_b.js",
      name: "app_b",
      remotes: {
        app_a: "app_a@http://localhost:3000/app_a.js",
      },
    }),
  ],
  devServer: {
    host: "localhost",
    port: 3001,
  },
};
